package javaMetaModel;

import java.util.ArrayList;
import java.util.List;
import javaMetaModel.visitor.IMetaModelVisitor;

public class Comments {

	private StringBuffer mContents = new StringBuffer();

	public Comments(String aString) {
		this.mContents.append(aString);
	}

	public Comments() {
		this("");
	}

	public void setComment(String aComment) {
		this.mContents = new StringBuffer();
		this.mContents.append(aComment);
	}

	public void addComment(String aComment) {
		this.mContents.append(aComment);
		this.mContents.append(System.getProperty("line.separator"));
	}

	public String getContents() {
		return this.mContents.toString();
	}

	public void accept(IMetaModelVisitor aVisitor) {
		aVisitor.visitComments(this);
	}

	public boolean isEmpty() {
		return this.getContents().isEmpty();
	}

	public List<String> getAllCommentLines() {
		List<String> allLines = new ArrayList<String>();

		String[] lineTable = this.getContents().split(
				System.getProperty("line.separator"));

		for (int i = 0; i < lineTable.length; i++) {
			allLines.add(lineTable[i]);
		}

		return allLines;
	}

	public boolean hasComment() {
		return !this.isEmpty();
	}
}
